package com.tony.mindhr.controller.system;

import com.tony.mindhr.model.Hr;
import com.tony.mindhr.model.RespBean;
import com.tony.mindhr.model.Role;
import com.tony.mindhr.service.HrServie;
import com.tony.mindhr.service.RoleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * Created with IntelliJ IDEA.
 *
 * @Title: HrController
 * @Auther: 皮蛋布丁
 * @Date: 2021/06/06/22:17
 * @Description:
 */
@RestController
@RequestMapping("/system/hr")
public class HrController {
    @Autowired
    HrServie hrServie;
    @Autowired
    RoleService roleService;

    /**
    * @Description: getAllHrs 获取所有操作用户信息
    * @Param: []
    * @return: java.util.List<com.tony.mindhr.model.Hr>
    * @Author: 皮蛋布丁
    * @Date: 2021/6/6 22:20
    */
    @GetMapping("/")
    public List<Hr> getAllHrs(String keywords) {
        return hrServie.getAllHrs(keywords);
    }


    /**
    * @Description: updateHr 更新操作用户信息
    * @Param: [hr]
    * @return: com.tony.mindhr.model.RespBean
    * @Author: 皮蛋布丁
    * @Date: 2021/6/8 21:23
    */
    @PutMapping("/")
    public RespBean updateHr(@RequestBody Hr hr) {
        if (hrServie.updateHr(hr) == 1) {
            return RespBean.ok("更新成功！");
        }
        return RespBean.error("更新失败！");
    }


    /**
    * @Description: getAllRoles 获取所有角色
    * @Param: []
    * @return: java.util.List<com.tony.mindhr.model.Role>
    * @Author: 皮蛋布丁
    * @Date: 2021/6/8 21:54
    */
    @GetMapping("/roles")
    public List<Role> getAllRoles() {
        return roleService.getAllroles();
    }


    /**
    * @Description: updateHrRoles 根据用户id更新角色列表
    * @Param: [hrid, rids]
    * @return: com.tony.mindhr.model.RespBean
    * @Author: 皮蛋布丁
    * @Date: 2021/6/10 20:36
    */
    @PutMapping("/role")
    public RespBean updateHrRoles(Integer hrid,Integer[] rids) {
        if (hrServie.updateHrRoles(hrid,rids)) {
            return RespBean.ok("更新成功！");
        }
        return RespBean.error("更新失败！");
    }

    /**
    * @Description: deletehrById 根据id删除hr
    * @Param: [id]
    * @return: com.tony.mindhr.model.RespBean
    * @Author: 皮蛋布丁
    * @Date: 2021/6/10 21:31
    */
    @DeleteMapping("/{id}")
    public RespBean deletehrById(@PathVariable Integer id) {
        if (hrServie.deletehrById(id) == 1) {
            return RespBean.ok("删除成功1");
        }
        return RespBean.error("删除失败！");
    }




}
